package 栈;

import java.util.Arrays;
import java.util.Stack;

/**
 * @Author：小鹿爱吃鱼
 * @Date: 2025/5/5 16:28
 * @Description:
 */
public class 有效的括号 {

    public static boolean isValid(String s) {
        String[] split = s.split("");
        Stack<String> stack = new Stack<>();
        if(split.length == 1){
            return false;
        }
        for (int i = 0; i < split.length; i++) {
            if(split[i].equals("(")){
                stack.push(")");
                continue;
            }
            if(split[i].equals("{")){
                stack.push("}");
                continue;
            }
            if(split[i].equals("[")){
                stack.push("]");
                continue;
            }

            // !stack.isEmpty() 很重要 很重要
            if(!stack.isEmpty() && split[i].equals(stack.peek())){
                stack.pop();
            }else{
                return false;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        System.out.println(isValid("([}}])"));
    }
}
